package zkclient;

import org.I0Itec.zkclient.ZkClient;
import org.apache.zookeeper.CreateMode;

public class Create_Node_Sample {
    public static void main(String[] args) {
        String ip = "192.168.200.20";
        int port = 8899;
        ZkClient zkClient = new ZkClient("192.168.200.20:2181");
        System.out.println("ZooKeeper session established.");
        //createParents的值设置为true，可以递归创建节点
        zkClient.createPersistent("/lg-rpc-provider",true);
        zkClient.create("/lg-rpc-provider/" + ip + ":" + port, true, CreateMode.EPHEMERAL);
        System.out.println("success create znode.");
        try {
            Thread.currentThread().wait();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
